﻿using PLCS.Domain.Shared.Stations;
using PLCS.EquipmentService.Methods;

namespace PLCS.Web.EventHandlers.Stations;

public class StationHaveStatusChangeExcuteMethodHandler : ILocalEventHandler<StationHaveStatusChangeEvent>, ITransientDependency
{
    private readonly ExecuteMethod _executeMethod;

    public StationHaveStatusChangeExcuteMethodHandler(ExecuteMethod executeMethod)
    {
        this._executeMethod = executeMethod;
    }

    public Task HandleEventAsync(StationHaveStatusChangeEvent eventData)
    {
        if (eventData.HaveStatus == Domain.Shared.Enums.YesNo.是 && !string.IsNullOrWhiteSpace(eventData.FullChangedMethod))
        {
            _executeMethod.ExecuteTriggerMethod("StationFullChangedMethod", eventData.FullChangedMethod, eventData.FullChangedParam);
        }
        else if (eventData.HaveStatus == Domain.Shared.Enums.YesNo.否 && !string.IsNullOrWhiteSpace(eventData.EmptyChangedMethod))
        {
            _executeMethod.ExecuteTriggerMethod("StatiionEmptyChangeMethod", eventData.EmptyChangedMethod, eventData.EmptyChangedParam);
        }
        return Task.CompletedTask;
    }
}